package com.qtyx.nms.util

import android.content.res.AssetManager
import com.google.gson.Gson
import com.qtyx.nms.MyApp
import com.qtyx.nms.mvp.model.bean.*
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import kotlin.random.Random


object JsonUtil {

    /**
     * 读取Asset的json字符串
     */
    fun getAssetJson(fileName: String): String {
        val stringBuilder = StringBuilder()
        try {
            val assetManager: AssetManager = MyApp.getMyAppContext().assets
            val bf = BufferedReader(InputStreamReader(assetManager.open(fileName)))
            var line: String?
            while (bf.readLine().also { line = it } != null) {
                stringBuilder.append(line)
            }
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return stringBuilder.toString()
    }

}


/**
 * 创建护理
 */
fun createNurse() {
    val list = mutableListOf<NurseBean.Data>()
    val data1 = NurseBean.Data("总人数", "", "", "1", getNurseDetail(87), "", 0, 1)
    val data2 = NurseBean.Data("今日入院", "", "", "1", getNurseDetail(12), "", 0, 1)
    val data3 = NurseBean.Data("今日出院", "", "", "1", getNurseDetail(5), "", 0, 1)
    val data4 = NurseBean.Data("一级护理", "", "", "1", getNurseDetail(7), "", 0, 1)
    val data5 = NurseBean.Data("病重", "", "", "1", getNurseDetail(3), "", 0, 1)
    val data6 = NurseBean.Data("病危", "", "", "1", getNurseDetail(1), "", 0, 1)
    val data7 = NurseBean.Data("吸氧2h", "", "", "1", getNurseDetail(8), "", 0, 1)
    val data8 = NurseBean.Data("吸氧6h", "", "", "1", getNurseDetail(1), "", 0, 1)
    val data9 = NurseBean.Data("血压TID", "", "", "1", getNurseDetail(4), "", 0, 1)

    val data10 = NurseBean.Data("遥测心电", "", "", "2", getNurseDetail(16), "", 0, 1)
    val data11 = NurseBean.Data("禁碘饮食", "", "", "2", getNurseDetail(5), "", 0, 1)
    val data12 = NurseBean.Data("尿管护理", "", "", "2", getNurseDetail(2), "", 0, 1)
    val data13 = NurseBean.Data("陪留人", "", "", "2", getNurseDetail(35), "", 0, 1)


    list.add(data1)
    list.add(data2)
    list.add(data3)
    list.add(data4)
    list.add(data5)
    list.add(data6)
    list.add(data7)
    list.add(data8)
    list.add(data9)
    list.add(data10)
    list.add(data11)
    list.add(data12)
    list.add(data13)

    val bean = NurseBean(list)
    print(Gson().toJson(bean))
}

private fun getNurseDetail(totalNum: Int): List<NurseBean.Data.SqlData> {
    val listSqlData = mutableListOf<NurseBean.Data.SqlData>()

    repeat(totalNum) {
        val random = Random.nextInt(50)
        val sqlData = NurseBean.Data.SqlData(
            "${random + 2}",
            "张三",
            "${it * 6}",
            "男",
            "李大夫",
            "小玉",
            "现金收费",
            100.0,
            Random.nextInt(1, 4),
            "",
            "",
            "",
            "",
            "",
            ""
        )
        listSqlData.add(sqlData)
    }
    return listSqlData
}


/**
 * 创建护理等级颜色
 */
fun createNurseGrade() {
    val list = listOf(
        NurseGradeBean.Data("1", "Ⅰ", "#04DBA6"),
        NurseGradeBean.Data("2", "Ⅱ", "#04DBA6"),
        NurseGradeBean.Data("3", "Ⅲ", "#04DBA6"),
    )
    val bean = NurseGradeBean(list)
    print(Gson().toJson(bean))
}

/**
 * 创建值班信息
 */
fun createZhiBan() {
    val list = listOf(
        ZhiBanBean.Data("<p><span style=\"color: rgb(249,150,59);\">值班护士：小玉</span>。&nbsp;&nbsp;<br></p>")
    )
    val bean = ZhiBanBean(list)
    print(Gson().toJson(bean))
}

/**
 * 创建消息信息
 */
fun createMessage() {
    val list = listOf(
        MessageBean.Data("1", "护理大屏培训，消息内容", "《护理大屏》培训会通知", "2020-12-26 08:30", 0),
        MessageBean.Data("2", "元旦消息内容", "关于元旦放假通知", "2020-12-31 10:00", 1),
    )
    val bean = MessageBean(list)
    print(Gson().toJson(bean))
}

/**
 * 创建医师信息
 */
fun createYiShi() {
    val list = mutableListOf<YiShiBean.Data>()

    repeat(5) {
        list.add(
            YiShiBean.Data(
                "$it",
                "张三$it",
                "${it + 10}",
                "男",
                "id$it",
                "李大夫$it",
                "小玉$it",
                "现金收费",
                999 * it.toDouble(),
                1,
                "",
                "",
                "",
                "",
                "",
                ""
            )
        )
    }

    val bean = YiShiBean(list)
    print(Gson().toJson(bean))
}


fun main(args: Array<String>) {
    createNurse()
}